﻿
<?php

   if(!empty($_POST)&&$_POST['fall']==2){

       $title=$_POST['title'];
       $content=$_POST['content'];
       $type=$_POST['type'];
    // print_r($type);die;
       $sql = "INSERT INTO `news`(`title`,`type`,`content`) VALUES ('$title','$type','$content')";

       mysqli_query($link,'set names utf8');
       mysqli_query($link,$sql);

       $xf=mysqli_affected_rows($link);
       echo  $xf ;
       die;
   }



    if(!empty($_POST)){
           // print_r($_FILES);

          $savePath = "";

      if(!empty($_FILES['file
        ']['name'][0])){
           // print_r($filelist);die;
           $filelist = array();
           foreach ($_FILES['file']['name'] as $key => $va) {
            $filelist[$key]['name']=$_FILES['file']['name'][$key];
            $filelist[$key]['type']=$_FILES['file']['type'][$key];
            $filelist[$key]['tmp_name']=$_FILES['file']['tmp_name'][$key];
            $filelist[$key]['error']=$_FILES['file']['error'][$key];
            $filelist[$key]['size']=$_FILES['file']['size'][$key];
           }
           // print_r($filelist);die;
            foreach ($filelist as $value) {

            $uploads = potting($value);

          // $uploads = thumb($value);
        }
}

// print_r($uploads);

         //把表单的值存放到这四个变量中
        $title=$_POST['title'];
        $type=$_POST['type'];
        $author=$_POST['author'];
        $content=$_POST['content'];
        $send_user=$_SESSION['admin']['name'];
        $add_time=time();
          //调用函数
        //print_r($filelist[0]);
        $url = potting($filelist[0]);

         //链接数据库

        // print_r($_POST);

        $sql = "INSERT INTO `news`(`title`,`type`,`author`,`content`,`news_photo`) VALUES ('$title','$type','$author','$content','$url')";
           mysqli_query($link,'set names utf8');
        mysqli_query($link,$sql);
       $xf=mysqli_affected_rows($link);


        // print_r($xf);
               //判断$xf的值是否大于0，大于则编辑成功
           if($xf>0){

               echo '<script>alert("编辑成功");location.href="index.php?c=news&a=list&admin=1"; </script>';

            }else{

        echo '<script>alert("编辑失败");history.go(-1) </script>';
      }
}




$id = empty($_GET['id'])?0:$_GET['id'];

      //查询顶级分类
      $sql = "select * from `cate` where pid=$id";
      $result =  mysqli_query($link,$sql);
      while ($arr = mysqli_fetch_assoc($result)) {
      $cate[] = $arr;
      }
  // print_r($cate);
  // echo($cate);
       if(!empty($_SERVER['HTTP_X_REQUESTED_WITH'])){

                echo json_encode($cate);die;
       }
 //载入后台公共视图
    include_once (VIEW_PATH.'admin/layout.html');
?>